package com.simple.framework.core.domain;

import com.simple.framework.constant.HttpStatus;
import lombok.Data;

/**
 * @Description 统一 响应类
 * @Author xiaoke
 * @Date 2024/8/10 18:00
 * @Version 1.0
 */
@Data
public class R<T> {
    private static final long serialVersionUID = 1L;

    /** 成功 */
    public static final int SUCCESS = HttpStatus.SUCCESS;

    /** 失败 */
    public static final int FAIL = HttpStatus.ERROR;

    private int code;

    private String msg;

    private T data;

    public R(int code, String msg, T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> R<T> success(){
        return new R<>(SUCCESS,"操作成功",null);
    }

    public static <T> R<T> success(T data){
        return new R<>(SUCCESS,"操作成功",data);
    }

    public static <T> R<T> success(int code, T data) {
        return new R<>(code,"操作成功",data);
    }

    public static <T> R<T> fail(){
        return new R<>(FAIL,"操作失败",null);
    }

    public static <T> R<T> fail(int code, String msg){
        return new R<>(code,msg,null);
    }

}
